home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / SICL / data1.cab / sicl32 / c / samples / misc / ser_intf.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-02  |  2.0 KB  |  62 lines

  1. /* ser_intf.c
  2.    This program does the following:
  3.    1) gets the current configuration of the serial port,
  4.    2) sets it to 9600 baud, no parity, 8 data bits, and
  5.       1 stop bit, and
  6.    3) Prints the old configuration.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <sicl.h>
  11.  
  12. main()
  13. {
  14.    INST intf;                 /* interface session id */
  15.    unsigned long baudrate, parity, databits, stopbits;
  16.    char *parity_str;
  17.  
  18.    #if defined(__BORLANDC__) && !defined(__WIN32__)
  19.       _InitEasyWin();   // required for Borland EasyWin programs
  20.    #endif
  21.  
  22.    /* Log message and exit program on error */
  23.    ionerror (I_ERROR_EXIT);
  24.  
  25.    /* open RS-232 interface session */
  26.    intf = iopen ("COM1");
  27.    itimeout (intf, 10000);
  28.  
  29.    /* get baud rate, parity, data bits, and stop bits */
  30.    iserialstat (intf, I_SERIAL_BAUD,   &baudrate);
  31.    iserialstat (intf, I_SERIAL_PARITY, &parity);
  32.    iserialstat (intf, I_SERIAL_WIDTH,  &databits);
  33.    iserialstat (intf, I_SERIAL_STOP,   &stopbits);
  34.  
  35.    /* determine string to display for parity */
  36.    if      (parity == I_SERIAL_PAR_NONE)   parity_str = "NONE";
  37.    else if (parity == I_SERIAL_PAR_ODD)    parity_str = "ODD";
  38.    else if (parity == I_SERIAL_PAR_EVEN)   parity_str = "EVEN";
  39.    else if (parity == I_SERIAL_PAR_MARK)   parity_str = "MARK";
  40.    else   /*parity == I_SERIAL_PAR_SPACE*/ parity_str = "SPACE";
  41.  
  42.    /* set to 9600,NONE,8,1 */
  43.    iserialctrl (intf, I_SERIAL_BAUD,   9600);
  44.    iserialctrl (intf, I_SERIAL_PARITY, I_SERIAL_PAR_NONE);
  45.    iserialctrl (intf, I_SERIAL_WIDTH,  I_SERIAL_CHAR_8);
  46.    iserialctrl (intf, I_SERIAL_STOP,   I_SERIAL_STOP_1);
  47.  
  48.    /* Display previous settings */
  49.    printf("Old settings:  %5ld,%s,%ld,%ld\n",
  50.       baudrate, parity_str, databits, stopbits);
  51.  
  52.    /* close port */
  53.    iclose (intf);
  54.  
  55. /* For WIN16 programs, call _siclcleanup before exiting to release
  56.    resources allocated by SICL for this application.  This call
  57.    is a no-op for WIN32 programs. */
  58.    _siclcleanup();
  59.  
  60.    return 0;
  61. }
  62.